//
//  ASDetailCardCell.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/30.
//

#import "ASDetailCardCell.h"

@implementation ASDetailCardCell

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.mainView];
        [self.mainView addSubview:self.mainImage];
        [self.mainView addSubview:self.borderView];
        [self setAllViewLayout];
    }
    return self;
}

- (void)setAllViewLayout{
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [self.mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [self.borderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
}

- (UIView *)mainView{
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.layer.masksToBounds = YES;
    }
    return _mainView;
}

- (UIImageView *)mainImage{
    if (!_mainImage) {
        _mainImage = [UIImageView new];
        _mainImage.contentMode = UIViewContentModeScaleAspectFill;
        _mainImage.clipsToBounds = YES;
        _mainImage.backgroundColor = [UIColor colorWithHexString:@"ffffff"];
    }
    return _mainImage;
}

- (UIView *)borderView{
    if (!_borderView) {
        _borderView = [UIView new];
        _borderView.layer.cornerRadius = 5;
        _borderView.layer.masksToBounds = YES;
        _borderView.layer.borderColor = [UIColor colorWithHexString:@"#FF7785"].CGColor;
        _borderView.layer.borderWidth = 1.f;
    }
    return _borderView;
}

- (void)setType:(ASDetailCardType)type{
    _type = type;
    if (type == ASDetailCardType_Square) {
        self.mainView.layer.cornerRadius = 5;
        self.borderView.layer.cornerRadius = 5;
        self.mainImage.layer.cornerRadius = 5;

    }else{
        self.mainView.layer.cornerRadius = (SCREEN_WIDTH - 80) / 2;
        self.borderView.layer.cornerRadius = (SCREEN_WIDTH - 80) / 2;
        self.mainImage.layer.cornerRadius = (SCREEN_WIDTH - 80) / 2;

    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
